package com.dz.controller;

import cn.hutool.json.JSONObject;
import com.dz.config.result.ResponseResult;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.io.IOException;

@Api(tags = "动态预警一张图")
@RestController
@RequestMapping("/dynamicWarningImage")
public class DynamicWarningController {

    @Resource
    private RestTemplate restTemplate;

    private final String PAYMENTURL = "http://localhost:8002/dynamicWarningImage/";

    /****
     * 查询天气预报  qxba01a  qxbb01a
     * @return
     */
    @ApiOperation(value = "查询三天天气预报(大屏)")
    @PostMapping("/queryThreeCityForecast")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "编码", required = true, defaultValue = "NDMwMDAw", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "名称", required = true, defaultValue = "5rmW5Y2X55yB", dataType = "String", paramType = "query")
    })
    public ResponseResult queryThreeCityForecast(@RequestBody JSONObject jsonObject) {
        return restTemplate.postForObject(PAYMENTURL + "queryThreeCityForecast", jsonObject,ResponseResult.class);
    }


    @ApiOperation(value = "地区及编码")
    @PostMapping("/queryLocationAndCode")
    @ResponseBody
    public ResponseResult queryLocationAndCode() {
        return restTemplate.postForObject(PAYMENTURL + "queryLocationAndCode", null,ResponseResult.class);
    }

    @ApiOperation(value = "三天天气预报")
    @PostMapping("/queryThreeDayWeatherForecast")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cityName", value = "怀化市", required = true, defaultValue = "怀化市", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "countyName", value = "县区名称(怀化市辖区)", required = true, defaultValue = "鹤城区", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "todayTime", value = "今日时间", required = true, defaultValue = "2023-11-21", dataType = "String", paramType = "query")
    })
    public ResponseResult queryThreeDayWeatherForecast(@RequestBody JSONObject jsonObject) {
        return restTemplate.postForObject(PAYMENTURL + "queryThreeDayWeatherForecast", jsonObject,ResponseResult.class);
    }

    @ApiOperation(value = "预警发布统计")
    @PostMapping("/queryWarningReleaseStatistics")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "monthYear", value = "年1月2", required = true, defaultValue = "年1/月2", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "time", value = "年月时间", required = true, defaultValue = "年2023/月2023-11", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "warningType", value = "预警类别", required = true, defaultValue = "全部%、中短期4、短期2、短临1", dataType = "String", paramType = "query")
    })
    public ResponseResult queryWarningReleaseStatistics(@RequestBody JSONObject jsonObject) {
        return restTemplate.postForObject(PAYMENTURL + "queryWarningReleaseStatistics", jsonObject,ResponseResult.class);
    }


    @ApiOperation(value = "动态临灾预警")
    @PostMapping("/queryDynamicNearDisasterWaring")
    @ResponseBody
    public ResponseResult queryDynamicNearDisasterWaring() throws IOException {
        return restTemplate.postForObject(PAYMENTURL + "queryDynamicNearDisasterWaring", null,ResponseResult.class);
    }


    @ApiOperation(value = "今日省份预警-短期")
    @PostMapping("/queryTodayProvinceShortWaring")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "time", value = "当日时间", required = true, defaultValue = "2023-09-06", dataType = "String", paramType = "query"),
    })
    public ResponseResult queryTodayProvinceShortWaring(@RequestBody JSONObject jsonObject) {
        return restTemplate.postForObject(PAYMENTURL + "queryTodayProvinceShortWaring", jsonObject,ResponseResult.class);
    }



    @ApiOperation(value = "今日省份预警-中短期")
    @PostMapping("/queryTodayProvinceMidShortWaring")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "time", value = "当日时间", required = true, defaultValue = "2023-10-07", dataType = "String", paramType = "query"),
    })
    public ResponseResult queryTodayProvinceMidShortWaring(@RequestBody JSONObject jsonObject) {
        return restTemplate.postForObject(PAYMENTURL + "queryTodayProvinceMidShortWaring", jsonObject,ResponseResult.class);
    }


    @ApiOperation(value = "最新监控")
    @PostMapping("/queryLatestMonitoring")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "time", value = "时间", required = true, defaultValue = "2023-11-27", dataType = "String", paramType = "query")
    })
    public ResponseResult queryLatestMonitoring(@RequestBody JSONObject jsonObject) {
        return restTemplate.postForObject(PAYMENTURL + "queryLatestMonitoring", jsonObject,ResponseResult.class);
    }

    @ApiOperation(value = "最新监控详细信息")
    @PostMapping("/queryLatestMonitoringInfo")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "time", value = "时间", required = false, defaultValue = "2023-06-30 09:09", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "endTime", value = "截至时间", required = false, defaultValue = "2023-07-30 09:09", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "county", value = "县", required = false, defaultValue = "沅陵县", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "waringLevel", value = "预警等级", required = false, defaultValue = "", dataType = "String", paramType = "query")
    })
    public ResponseResult queryLatestMonitoringInfo(@RequestBody JSONObject jsonObject) {
        return restTemplate.postForObject(PAYMENTURL + "queryLatestMonitoringInfo", jsonObject,ResponseResult.class);
    }


    @ApiOperation(value = "预报监控")
    @PostMapping("/queryforecastMonitoring")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "time", value = "时间", required = true, defaultValue = "2023-11-27", dataType = "String", paramType = "query")
    })
    public ResponseResult queryforecastMonitoring(@RequestBody JSONObject jsonObject) {
        return restTemplate.postForObject(PAYMENTURL + "queryforecastMonitoring", jsonObject,ResponseResult.class);

    }


    @ApiOperation(value = "左实况降水图片")
    @ResponseBody
    @PostMapping("/getPngFilesByDateTime")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "time", value = "时间(空字符串则查pg、传入时间则按照时间查格式2023-11-16 17:00:00)", required = true, defaultValue = "", dataType = "String", paramType = "query")
    })
    public ResponseResult downloadPngFiles(@RequestBody JSONObject jsonObject) {
        return restTemplate.postForObject(PAYMENTURL + "getPngFilesByDateTime", jsonObject,ResponseResult.class);
    }

    @ApiOperation(value = "左实况降水信息")
    @PostMapping("/queryPrecipitationInfoByTimeAndName")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startTime", value = "开始时间", required = true, defaultValue = "2023-11-16 10:00:00", dataType = "Date", paramType = "query"),
            @ApiImplicitParam(name = "endTime", value = "结束时间", required = true, defaultValue = "2023-11-16 10:00:00", dataType = "Date", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "县名称", required = true, defaultValue = "洪江区", dataType = "String", paramType = "query")
    })
    public ResponseResult queryPrecipitationInfoByTimeAndName(@RequestBody JSONObject jsonObject) {
        return restTemplate.postForObject(PAYMENTURL + "queryPrecipitationInfoByTimeAndName", jsonObject,ResponseResult.class);

    }


    /**
     * 根据时间段、站点编号查询逐小时降水以及逐小时累积
     */
    @ApiOperation(value = "左逐小时降水以及逐小时累积")
    @PostMapping("/queryFallingWaterGrowingByTimeAndStationCode")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startTime", value = "开始时间", required = true, defaultValue = "2023-06-29 02:00:00", dataType = "Date", paramType = "query"),
            @ApiImplicitParam(name = "endTime", value = "结束时间", required = true, defaultValue = "2023-07-01 07:00:00", dataType = "Date", paramType = "query"),
            @ApiImplicitParam(name = "stationCode", value = "站点编号", required = true, defaultValue = "P4105", dataType = "String", paramType = "query")
    })
    public ResponseResult queryFallingWaterGrowingByTimeAndStationCode(@RequestBody JSONObject jsonObject) {
        return restTemplate.postForObject(PAYMENTURL + "queryFallingWaterGrowingByTimeAndStationCode", jsonObject,ResponseResult.class);
    }


    /**
     * 预报1个接口
     * 根据时间查询图片（时间未传 查询ggcf01a 得到时间）
     */
    @ApiOperation(value = "左预报降水图片")
    @PostMapping("/queryForecastFallingWaterByTime")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "time", value = "时间yyyy-MM-dd", required = true, defaultValue = "2023-11-28", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "nTime", value = "时次8/20", required = true, defaultValue = "8", dataType = "String", paramType = "query")
    })
    public ResponseResult queryForecastFallingWaterByTime(@RequestBody JSONObject jsonObject) {
        return restTemplate.postForObject(PAYMENTURL + "queryForecastFallingWaterByTime", jsonObject,ResponseResult.class);
    }


    /**
     * 雷达图
     * 查询最近10张雷达图
     * 省级pg库 qxab02b 根据日期时次倒序取10张 得到qxab02b100编号 去省级mg库image_rader_png_file 根据编号查询图片
     */
    @ApiOperation(value = "雷达图")
    @PostMapping("/queryRadarChat")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startTime", value = "开始时间", required = true, defaultValue = "2023-06-29 02:00:00", dataType = "Date", paramType = "query"),
            @ApiImplicitParam(name = "endTime", value = "结束时间", required = true, defaultValue = "2023-07-01 07:00:00", dataType = "Date", paramType = "query"),
    })
    public ResponseResult queryRadarChat(@RequestBody JSONObject jsonObject) {
        return restTemplate.postForObject(PAYMENTURL + "queryRadarChat", jsonObject,ResponseResult.class);

    }


    /**
     * 云图
     * 查询最近10张云图
     * 省级pg库qxab03a 根据日期时次倒序取10张 得到qxab03a100编号 去省级mg库image_rader_png_file 根据编号查询图片
     */
    @ApiOperation(value = "云图")
    @PostMapping("/queryCloudChat")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startTime", value = "开始时间", required = true, defaultValue = "2023-06-29 02:00:00", dataType = "Date", paramType = "query"),
            @ApiImplicitParam(name = "endTime", value = "结束时间", required = true, defaultValue = "2023-07-01 07:00:00", dataType = "Date", paramType = "query"),
    })
    public ResponseResult queryCloudChat(@RequestBody JSONObject jsonObject) {
        return restTemplate.postForObject(PAYMENTURL + "queryCloudChat", jsonObject,ResponseResult.class);

    }


    /**
     * 服务产品
     * 查询最近10个产品
     * 省级PG库qxbb01a
     * 根据qxbb01a060的编号去省级mg库里查询文件pdf_service_product
     */
    @ApiOperation(value = "服务产品")
    @PostMapping("/queryServiceProduct")
    @ResponseBody
    public ResponseResult queryServiceProduct() {
        return restTemplate.postForObject(PAYMENTURL + "queryServiceProduct", null,ResponseResult.class);
    }


}

